<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            background-color: skyblue;
            /* 1. padding: 25% 0; */
            /* 前提 宽度是 viewport */
            /* height: 50vw; */
        }
    </style>
</head>
<body>
    <div class="box">
    </div>
    <script>
        const oBox = document.querySelector(".box");
        window.onload = function(){
            oBox.style.height = (oBox.offsetWidth/2) + 'px';
            // 回流
        }
        window.onresize = function(){
            oBox.style.height = (oBox.offsetWidth/2) + 'px';
            // 加个防抖
        }
    </script>
</body>
</html>